package com.ssly.media.manage.controller.api;

import com.ssly.media.manage.configuration.MediaProperties;
import com.ssly.media.manage.domain.ConvertTask;
import com.ssly.media.manage.domain.DownTask;
import com.ssly.media.manage.domain.SourceMedia;
import com.ssly.media.manage.ffmpeg.Media;
import com.ssly.media.manage.ffmpeg.MediaConverter;
import com.ssly.media.manage.repository.ConvertTaskRepository;
import com.ssly.media.manage.repository.DownTaskRepository;
import com.ssly.media.manage.repository.SourceMediaRepository;
import com.ssly.media.manage.service.ConvertTaskService;
import com.ssly.media.manage.service.TargetMediaService;
import com.ssly.media.manage.util.JsonResult;
import com.ssly.media.manage.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.datatables.mapping.DataTablesInput;
import org.springframework.data.jpa.datatables.mapping.DataTablesOutput;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.sql.Timestamp;

import static java.lang.Thread.sleep;


@RestController
@RequestMapping("api/convert-task")
public class ConvertTaskController {

    @Autowired
    private ConvertTaskRepository convertTaskRepository;
    @Autowired
    private ConvertTaskService convertTaskService;

    @GetMapping("/{id}")
    public JsonResult show(@PathVariable Integer id) {
        return R.success();
    }

    @GetMapping
    public DataTablesOutput<ConvertTask> index(DataTablesInput input) {
        return convertTaskRepository.findAll(input);
    }

    @PutMapping
    public JsonResult update() {
        return R.success();
    }

    @PostMapping
    public JsonResult create(ConvertTask convertTask) {
        convertTaskService.create(convertTask);
        return R.success("任务创建成功！稍后请在转码任务管理界面查看转码进度");
    }

    @DeleteMapping("/{id}")
    public JsonResult delete(@PathVariable Integer id) {
        convertTaskRepository.deleteById(id);
        return R.success("删除成功");
    }

}
